package com.yida.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.yida.common.core.utils.poi.ExcelUtil;
import com.yida.common.core.web.controller.BaseController;
import com.yida.common.core.web.domain.AjaxResult;
import com.yida.common.core.web.page.TableDataInfo;
import com.yida.common.log.annotation.Log;
import com.yida.common.log.enums.BusinessType;
import com.yida.common.security.annotation.RequiresPermissions;
import com.yida.system.api.domain.SysBlackList;
import com.yida.system.domain.request.SysWhiteListEditRequest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import com.yida.system.api.domain.SysWhiteList;
import com.yida.system.service.ISysWhiteListService;


/**
 * 系统白名单Controller
 * 
 * @author wws
 * @date 2023-03-22
 */
@RestController
@RequestMapping("/system/white")
@Api(tags = "系统白名单管理")
public class SysWhiteListController extends BaseController
{
    @Autowired
    private ISysWhiteListService sysWhiteListService;

    /**
     * 查询系统白名单列表
     */
    @RequiresPermissions("system:white:list")
    @GetMapping("/list")
    @ApiOperation(value = "分页查询",response = SysBlackList.class)
    public TableDataInfo list(SysWhiteList sysWhiteList)
    {
        startPage();
        List<SysWhiteList> list = sysWhiteListService.selectSysWhiteListList(sysWhiteList);
        return getDataTable(list);
    }

    /**
     * 导出系统白名单列表
     */
    @RequiresPermissions("system:white:export")
    @Log(title = "系统白名单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation("导出")
    public void export(HttpServletResponse response, SysWhiteList sysWhiteList)
    {
        List<SysWhiteList> list = sysWhiteListService.selectSysWhiteListList(sysWhiteList);
        ExcelUtil<SysWhiteList> util = new ExcelUtil<SysWhiteList>(SysWhiteList.class);
        util.exportExcel(response, list, "系统白名单数据");
    }

    /**
     * 获取系统白名单详细信息
     */
    @RequiresPermissions("system:white:list")
    @GetMapping(value = "/{id}")
    @ApiOperation(value = "详情",response = SysWhiteList.class)
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(sysWhiteListService.selectSysWhiteListById(id));
    }

    /**
     * 新增系统白名单
     */
    @RequiresPermissions("system:white:save")
    @Log(title = "系统白名单", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增")
    public AjaxResult add(@ApiParam(name = "ipAddress") @RequestParam String ipAddress)
    {
        return toAjax(sysWhiteListService.insertSysWhiteList(ipAddress));
    }

    /**
     * 修改系统白名单
     */
    @RequiresPermissions("system:white:edit")
    @Log(title = "系统白名单", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改")
    public AjaxResult edit(@RequestBody @Validated SysWhiteListEditRequest editRequest)
    {
        return toAjax(sysWhiteListService.updateSysWhiteList(editRequest));
    }

    /**
     * 删除系统白名单
     */
    @RequiresPermissions("system:white:delete")
    @Log(title = "系统白名单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    @ApiOperation("删除")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sysWhiteListService.deleteSysWhiteListByIds(ids));
    }
}
